<template>
	<div class="threePic" v-if="threePicData.length>0">
		<div class="ThreePicimg" v-if="threePicData" v-for="(item, index) in threePicData" :key="index">
			<img v-lazy="item.publicityPicture" @click='jumpEvent(item)' src="static/image/demo1.png" />
		</div>
		<div style="clear: both;"></div>
	</div>
</template>

<script>
	import { NAVIGATE } from "../../config/postMessage-types";
	import handlePath from "../../utils/lxn/handlePath";
	import {mapGetters} from "vuex";
	export default {
		props: {
			threePicData: {
				type: Array,
				default: () => []
			},
		},
		data() {
			return {
			}
		},
		methods: {
			jumpEvent(item) {
				if(item.extendField && !this.isApp) {
					if(JSON.parse(item.extendField).urldata) {
						var urldata2 = JSON.parse(item.extendField).urldata
						this.$router.push({
							path: 'NewOtherPage?urlData=' + urldata2
						})
						localStorage.setItem("otherpagetitle", item.relSubtitle)
					} else if(JSON.parse(item.extendField).url) {
						// var urldata1 = JSON.parse(item.extendField).url.path
						var urldata1 = handlePath(item)
						if(urldata1) {
							this.$router.push({
								name: "MiddleWare",
								params: {
									pageName: urldata1
								}
							})
						}
					}

				}else if(item.extendField && this.isApp){
					var urldata = JSON.parse(item.extendField).url
					if(urldata.valueArray[0] == '商品详情页面' ) {
						this.gotornpage('Detail', urldata.path.split("=")[1])
					} else if(urldata.valueArray[0] == '分类页面'){
						this.gotornpage('GoodsClassify', urldata.path.split("=")[1])
					}else if(urldata.valueArray[0] == '其他页面') {
						if(urldata.path == 'IntegralBuy') {
							if(this.hasUserInfo ===0) {
								this.gotornpage('Login')
							}else{
								this.gotornpage(urldata.path)
							}
						}else if(urldata.path == 'Coupons'){
							this.gotornpage('CouponsAcquire')
						} else if (urldata.path == 'buyGiftCard') {
							if(this.hasUserInfo ===0) {
								this.gotornpage('Login')
							} else{
								this.gotornpage('BuyGiftCard')
							}
						} else if(urldata.path == 'foodChecked'){
							if(this.hasUserInfo ===0) {
								this.gotornpage('Login')
							}
							else{
								this.gotornpage('FoodCheck')
							}
						} else if(urldata.path == 'prize_card'){
								if(this.hasUserInfo ===0) {
									this.gotornpage('Login')
								} else {
								this.$router.push({
									name: "MiddleWare",
									params: {
										pageName: urldata.path
									}
								})
							}
						} else if(urldata.path == 'integral'){
							console.log("urldata.path",urldata.path)
								if(this.hasUserInfo ===0) {
									this.gotornpage('Login')
								} else {
								this.$router.push({
									name: "MiddleWare",
									params: {
										pageName: urldata.path
									}
								})
							}
						} else if(urldata.path == 'login'){
							this.gotornpage('Login')
						} else if(urldata.path == 'register'){
							this.gotornpage('Regrester')
						} else {
							this.$router.push({
								name: "MiddleWare",
								params: {
									pageName: urldata.path
								}
							})
						}
					}
				}
			},
			gotornpage(page, code) {
				let params = {}
				if(page=='Detail'){
					params = {
						screen: page,
						params:{
							goodsCode: code
						}
					}
				}else if(page=='GoodsClassify'){
					params = {
						screen: page,
						params:{
							classCode: code
						}
					}
				}else{
					params = {
						screen: page,
					}
				}
				let goBackIns = {
					type: NAVIGATE,
					params:params
				}
				window.postMessage(JSON.stringify(goBackIns));
			}
		},
		created() {

		},
		computed: {
			isApp() {
				return window.isApp;
			},
			...mapGetters('wxh', [
                'userInfo'
            ]),
            hasUserInfo() {
                return Object.keys(this.userInfo).length;
            },
		},
		mounted() {

		}
	}
</script>

<style scoped>
	.threePic {
		padding: 0.5rem 0.2rem;
		text-align: center;
		margin: 0rem auto;
	}
	
	.threePic .ThreePicimg {
		float: left;
		margin: 0rem 1%;
		width: 31.33%;
	}
	
	.threePic .ThreePicimg img {
		max-width: 100%;
		margin: 0 auto;
	}
</style>